package com.sghd.football.robot.listenner;

import com.sghd.common.socket.anno.*;
import com.sghd.common.utils.json.JsonUtils;
import com.sghd.football.module.game.facade.model.GameResult;
import com.sghd.football.module.game.facade.model.JoinResult;
import com.sghd.football.robot.core.Controller;
import com.sghd.football.utils.SocketEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

import static com.sghd.common.socket.session.SessionKeys.IDENTITY;

/**
 * @author wch
 * @date 2018-07-06 12:09
 * @desc 接收服务端推送
 **/
@Component
@SocketModule
public class PushReceiver {
    private Logger logger = LoggerFactory.getLogger(PushReceiver.class);
    @Autowired
    private Controller controller;

    @SocketCommand(SocketEnum.UPDATE_P)
    public void pool(@InSession(IDENTITY) long robotId, @ToMap Map<String, Object> params){
        //接收奖池推送
    }
    @SocketCommand(SocketEnum.JOIN_ROOM)
    public void initDesk(@InSession(IDENTITY) long robotId, JoinResult joinResult){
        logger.debug("机器人[{}]->进入房间！", robotId);
        logger.debug("{}", JsonUtils.object2String(joinResult));
        controller.initDesk(robotId, joinResult.getMyName());
    }

    /**服务器结算完成*/
    @SocketCommand(SocketEnum.COMPLETE)
    public void complete(@InSession(IDENTITY) long robotId, @InBody("type") Integer type){
        controller.complete(robotId, type);
    }

    @SocketCommand(SocketEnum.OPERATRO)
    public void operator(@InSession(IDENTITY) long robotId, GameResult result){
        controller.operator(robotId, result);
    }

    @SocketCommand(SocketEnum.MINI_GAME)
    public void mini(@InSession(IDENTITY) long robotId, @InBody("money") long money){
        controller.mini(robotId, money);
    }
}
